html {
  box-sizing: border-box;
  //根元素字体大小；10 / 16 = 62.5%，采用rem单位时，1rem = 10px
  font-size: 62.5%;
}
* {
  margin: 0;
  padding: 0;
  box-sizing: inherit;
  &:before,
  &:after {
    box-sizing: inherit;
  }
}
body {
  width: 100%;
  height: 100vh;
  background-color: #111;
  color: #fff;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 1rem;
}

// Theming
$primary: magenta !default;
$secondary: cyan !default;
$white: #fff !default;
$black: #000 !default;
$dark: #2c2d2f !default;
$gray: gray !default;
// Accessible Semantic SCSS / Vanilla Number Input Knob / Potentiometer
$knob-d: 4em !default;
$knob-c: $gray !default;
$knob-spacing: 0.5em !default;
$knob-border-c: #181b1c !default;
$knob-border-w: 0.5em !default;
$knob-bg-c: $dark !default;
$knob-ind-c: #888 !default;
$knob-ind-focus-c: $primary !default;
$knob-label-c: #e4e8ea !default;
$knob-group-border-r: 0.2rem !default;
$knob-group-bg-c: $dark !default;
$knob-font: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono",
  "Courier New", monospace !default;

.wrapper {
  margin: 50px auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  user-select: none;
  touch-action: none;
  form {
    margin: 0 0 1em 0;
    &:last-of-type {
      margin-bottom: 0;
    }
  }
}

.knob-group {
  position: relative;
  display: inline-block;
  background-color: $knob-group-bg-c;
  padding: 0 $knob-spacing;
  border-radius: $knob-group-border-r;
  font-family: $knob-font;
  legend {
    position: relative;
    display: block;
    width: auto;
    line-height: 1.5;
    text-align: left;
    padding: $knob-spacing $knob-spacing calc($knob-spacing / 2) $knob-spacing;
    white-space: nowrap;
    background-color: $knob-group-bg-c;
    z-index: 2;
    outline: 0;
    &::before {
      content: "";
      position: relative;
      display: block;
      height: $knob-spacing;
      width: $knob-spacing;
      float: left;
      border-radius: 50%;
      background-color: $knob-ind-focus-c;
      cursor: pointer;
      transition: background 0.2s linear;
      margin: $knob-spacing calc($knob-spacing / 2) 0 calc($knob-spacing / -2);
    }
    &::after {
      position: absolute;
      font-size: 0.5em;
      padding: 0.5em 1em;
      background-color: $knob-bg-c;
      font-weight: 600;
      right: calc($knob-spacing/4);
      top: $knob-spacing * 1.25;
    }
    &:focus {
      &::before {
        box-shadow: 0 0 0 0.2em rgba($knob-ind-focus-c, 0.25);
      }
      &-visible {
        &::after {
          content: attr(data-key);
        }
      }
    }
  }
  hr {
    position: absolute;
    display: inline-block;
    width: calc(100% - $knob-spacing * 2);
    margin: 0;
    padding: 0;
    top: $knob-spacing * 2.5;
    right: $knob-spacing;
    border: 0;
    border-top: 1px solid currentColor;
    z-index: 1;
  }
  .knob {
    --knob-deg: 0;
    display: inline-block;
    position: relative;
    margin: 0;
    padding: 0;
    padding-bottom: 2em;
    width: $knob-d;
    border: 0;
    text-align: center;
    touch-action: none;
    font-size: 1rem;
    &.knob-small {
      font-size: 0.75rem;
    }
    &.knob-balance {
      hr,
      i {
        position: absolute;
        top: calc($knob-d / 0.65 - 1em);
        left: 0;
        width: 100%;
        border: 0;
        font-size: 0.65em;
        font-style: normal;
        line-height: 2.5;
        color: $knob-ind-c;
        &::before,
        &::after {
          position: absolute;
        }
        &::before {
          content: attr(data-min);
          left: 0;
        }
        &::after {
          content: attr(data-max);
          right: 0;
        }
      }
    }
    svg {
      path {
        stroke-dasharray: 87 10 87;
        &:last-of-type {
          stroke-dashoffset: 0;
        }
      }
    }

    input {
      appearance: textfield;
      position: relative;
      left: 0;
      top: 0;
      display: block;
      width: calc($knob-d / 0.75);
      height: $knob-border-w * 3;
      font: inherit;
      font-size: 0.75em;
      line-height: 1em;
      color: currentColor;
      font-variant-numeric: tabular-nums lining-nums;
      background-color: transparent;
      border: 0;
      margin: calc($knob-d / 0.75 + 0.5em) 0 0 0;
      padding: 0 !important;
      outline: 0;
      cursor: default;
      z-index: 2;
      caret-color: currentColor;
      &::placeholder {
        opacity: 1;
        color: currentColor;
      }
      &::selection {
        color: currentColor;
        background-color: rgba($knob-ind-focus-c, 0);
      }
      &::-webkit-outer-spin-button,
      &::-webkit-inner-spin-button {
        -webkit-appearance: none;
        margin: 0;
      }
      &:focus_ {
        color: currentColor;
        background-color: $knob-ind-focus-c;
      }
    }

    &[disabled],
    &[readonly] {
      cursor: not-allowed;
      & ~ *,
      & ~ *::before,
      & ~ *::after {
        pointer-events: none;
      }
      &::selection {
        background-color: transparent;
      }
    }

    label {
      position: absolute;
      left: 0;
      top: 0;
      display: inline-block;
      width: 100%;
      height: 100%;
      overflow: hidden;
      padding-top: $knob-d + 2em;
      font-size: 1em;
      white-space: nowrap;
      text-overflow: ellipsis;
      z-index: 1;
      &::before,
      &::after {
        position: absolute;
        display: inline-block;
      }
      &::before {
        content: "";
        left: 50%;
        top: $knob-border-w;
        width: $knob-d - $knob-border-w;
        height: $knob-d - $knob-border-w;
        border: $knob-border-w solid $knob-border-c;
        border-radius: 50%;
        background-color: transparent;
        background: linear-gradient(to bottom, currentColor 0% 100%) no-repeat
          50% 0%;
        background-size: 0.2em 1em;
        transform-origin: center;
        transform: translateX(-50%) rotate(0);
        transform: translateX(-50%) rotate(calc(1deg * var(--knob-deg)));
        cursor: default;
        pointer-events: fill;
      }
      &::after {
        content: attr(data-unit);
        top: calc($knob-d / 0.65 - 1.1em);
        right: 0;
        font-size: 0.65em;
        line-height: 2.5;
        color: $knob-ind-c;
      }
    }

    svg {
      position: absolute;
      left: 50%;
      top: 0;
      transform: translateX(-50%);
      stroke-dasharray: 184 184;
      fill: none;
      stroke: currentColor;
      z-index: 3;
      width: $knob-d + $knob-border-w;
      height: $knob-d + $knob-border-w;
      path {
        stroke-width: 5;
        stroke-dashoffset: 0;
        visibility: visible;
        pointer-events: stroke;
        transition: all 0.2s cubic-bezier(0, 0, 0.2, 1);
        &:first-of-type {
          stroke: $knob-ind-focus-c;
        }
        &:last-of-type {
          stroke: $knob-ind-c;
          stroke-dashoffset: -97;
        }
      }
    }
  }
}
